package store;

import java.util.ArrayList;

import note.*;

public class NoteStore implements Store {
    private ArrayList<Note> noteDB = new ArrayList<Note>();

    @Override
    public void storeNote(String text) throws Exception {
        try {
            TextNote note = new TextNote(text);
            noteDB.add(note);

            // exceptions may exist when this project got upgraded
            // for example, to check if same note already exist
            // same for next method
        } catch (Exception e) {
            throw e;
        }
    }

    @Override
    public void storeNote(String text, String url) throws Exception {
        try {
            TextAndImageNote note = new TextAndImageNote(text, url);
            noteDB.add(note);
        } catch (Exception e) {
            throw e;
        }
    }

    @Override
    public ArrayList<TextNote> getAllTextNotes() {
        ArrayList<TextNote> list = new ArrayList<>();
        for (Note note : noteDB) {
            if (note.getClass().getName() == "note.TextNote") {
                list.add((TextNote) note);
            }
        }
        return list;
    }

    @Override
    public ArrayList<TextAndImageNote> getAllTextAndImageNotes() {
        ArrayList<TextAndImageNote> list = new ArrayList<>();
        for (Note note : noteDB) {
            if (note.getClass().getName() == "note.TextAndImageNote") {
                list.add((TextAndImageNote) note);
            }
        }
        return list;
    }
}
